home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Python 1.3 / Python 1.3 PPC / Lib / mac / tlist.py < prev   
Encoding:
Python Source  |  1995-10-11  |  1.5 KB  |  64 lines  |  [TEXT/PYTH]

  1. # Test List module.
  2. # Draw a window with all the files in the current folder.
  3. # double-clicking will change folder.
  4. #
  5. # This test expects Win, Evt and FrameWork (and anything used by those)
  6. # to work.
  7.  
  8. import FrameWork
  9. import os
  10.  
  11. def filllist(l):
  12.     """Fill the list with the contents of the current directory"""
  13.     l.DoDraw(0)
  14.     l.DelRow(0)
  15.     contents = os.listdir(':')
  16.     l.AddRow(len(contents), 0)
  17.     for i in range(len(contents)):
  18.         l.SetCell(contents[i], (i, 0))
  19.     l.DoDraw(1)
  20.  
  21. class TestList(Application):
  22.     def __init__(self):
  23.         self.makemenubar()
  24.         self.makewindow()
  25.     
  26.     def makewindow(self):
  27.         r = (40, 40, 400, 300)
  28.         w = Win.NewWindow(r, "List test", 1, 0, -1, 1, 0x55555555)
  29.         r2 = (0, 0, 360, 260)
  30.         self.list = List.LNew(r2, (0, 0, 0, 0), (0,0), 0, w, 0, 1, 1, 1)
  31.         filllist(self.list)
  32.         
  33.     def makeusermenus(self):
  34.         self.filemenu = m = Menu(self.menubar, "File")
  35.         self.quititem = MenuItem(m, "Quit", "Q", self.quit)
  36.     
  37.     def quit(self, *args):
  38.         raise self
  39.  
  40.     def do_about(self, id, item, window, event):
  41.         EasyDialogs.Message("""Test the List Manager interface.
  42.         Double-click on a folder to change directory""")
  43.         
  44.     def do_update(self, *args):
  45.         self.list.LUpdate()
  46.  
  47.     def do_inContent(self, partcode, window, event):
  48.         (what, message, when, where, modifiers) = event
  49.         local = GlobalToLocal(where)
  50.         dclick = self.list.LClick(local, modifiers)
  51.         if dclick:
  52.             h, v = self.list.LLastClick()
  53.             file = self.list.LGetCell(1000, (h, v))
  54.             os.chdir(file)
  55.             filllist(self.list)
  56.  
  57. def main():
  58.     App = TestList()
  59.     App.mainloop()
  60.     
  61. if __name__ == '__main__':
  62.     main()
  63.     
  64.